/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controle;

import Util.MailSender;
import Util.PropertiesManager;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Fellipe de Souza
 */

@WebServlet(name = "trataErro", urlPatterns = {"/trataErro"})
public class trataErro extends Comando {

    public void execute() throws ServletException, IOException, SQLException {
        getResponse().setContentType("text/html;charset=UTF-8");
        PrintWriter out = getResponse().getWriter();
        try {
            
            HashMap dados = new PropertiesManager("email.properties").readPropertiesFile();
            String username = (String) dados.get("username");            
            String password = (String) dados.get("password");
            String porta = (String) dados.get("porta");
            String host = (String) dados.get("host");
            
            MailSender sender = new MailSender(username, password, host, porta);
            String mensagem = getRequest().getParameter("erro");
            sender.sendMail("Erro na aplicacao", mensagem);
            
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet trataErro</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet trataErro at " + getRequest().getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } catch (Exception ex) {    
            throw new ServletException(ex);
        }
    }

}
